<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Mass_email extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model(array('admin_commoncall','admin_settings_model'));

		$this->admin_commoncall->check_admin_login();
		$this->template->set_theme('admin');
		$this->template->set_layout('default');
		//$this->template->set_partial('side_menu','layouts/side_menu');
		//$this->template->set_partial('nav_bar','layouts/nav_bar');

	}

	function index()
	{
		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		->set_partial('footer','footer/footer')
		->build('promotion/mass_email');
	}

	function send_mass_email() {
		
		
		if ($this->input->post('email_send')) {
			$this->form_validation->set_rules('title', 'title', 'required|xss_clean');
			$this->form_validation->set_rules('email_description', 'body is empty', 'required|xss_clean');
		}
		if ($this->form_validation->run()) {
			$message = trim($this->input->post('email_description'));
			$i = 0;
			foreach ($listing as $listing): {
					if ($listing->email) {
						$title = $this->admin_settings_model->get_setting('webtitle');
						$this->admin_commoncall->send_mail($listing->email, $title, $message);
						print $listing->email;
					}
				$i++;
			}
			endforeach;
			$this->session->set_flashdata('message', 'Email Send :' . $i);
			redirect('secure/promotion/mass_email');
		}
		else {
			$this->template->title('Welcome', 'Ypage.com')
			->set_partial('nav_bar','layouts/nav_bar')
			->set_partial('side_menu','layouts/side_menu')
			->set_partial('footer','footer/footer')
			->build('promotion/mass_email');
		}

	}

}